package maple.core.contextproviders;

import maple.core.ContextProvider;
import maple.util.Context;
import maple.util.Sensor;

public class SimpleIlluminationLevel extends ContextProvider
{
	private double _threshold;

	public SimpleIlluminationLevel()
	{
		super( 1 );

		// from Consumer
		_preconditions.add( Sensor.Type.PHIDGET_LIGHT.toString() ); 
		_postcondition = Context.Type.ILLUMINATIONLEVEL.toString();

		_threshold = -1;
	}

	protected void setup()
	{
		super.setup();

		_threshold = Double.parseDouble( _arguments[ 1 ] );
	}

	protected String interpret()
	{
		String il = _preconditions.get( 0 );
		double illumination_level = Double.parseDouble( Sensor.toString( il, _perceptions.get( il ) ) );
	
		if( illumination_level < 0 )
		{
			return ContextProvider.State.UNKNOWN.toString();
		}
		else if( illumination_level > _threshold )
		{
			return Context.IlluminationLevel.HIGH.toString();
		}
		return Context.IlluminationLevel.LOW.toString();
	}
}
